import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/input_item.dart';
import 'package:xinxuan/common/input_item_sms_code.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/login_controller/login_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';

class UpdatePasswordPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '修改密码',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<LoginPageController>(
        init: LoginPageController(),
        builder: (controller) {
          return Obx(() => ScrollConfigurationCommon(child: ListView(
            children: [
              InputItem(
                title: '新密码', 
                hintText: '密码必须包含字母和数字',
                defaultValue: controller.password.value,
                showErrorText: !controller.checkPassword.value,
                errorText: '密码包含字母和数字',
                maxLength: 11,
                obscureText: true,
                onChenge: (String value) {
                  controller.password.value = value;
                  controller.checkUpdatePassword();
                }
              ),
              InputItem(
                title: '确认密码', 
                hintText: '请确认新密码',
                defaultValue: controller.confirmPassword.value,
                showErrorText: !controller.checkConfirmPassword.value,
                errorText: '密码不一致',
                maxLength: 11,
                obscureText: true,
                onChenge: (String value) {
                  controller.confirmPassword.value = value;
                  controller.checkConfirmPasswordFun();
                }
              ),
              InputItemSmsCode(
                duration: controller.duration.value,
                value: controller.verificationCode.value,
                onChenge: (String value) {
                  controller.verificationCode.value = value;
                }, 
                onTap: () {
                  if (controller.duration.value >= controller.totalDuration) {
                    controller.mobile.value = commonPageController.userData.value.mobile!;
                    controller.getSmsCode('password');
                  }
                }, 
              ),
              Container(
                margin: EdgeInsets.only(top: 54.h),
                padding: EdgeInsets.symmetric(horizontal: 25.w),
                child: ButtonUtil(
                  text: '保存', 
                  fontSize: 16.w, 
                  borderRadius: 30.w, 
                  height: 36.h, 
                  onTop: () {
                    controller.editPassword();
                  }
                ),
              )
            ],
          )));
        },
      ),
    );
  }
}